from sqlalchemy.orm import sessionmaker
from wordcloud import WordCloud
import PIL.Image as image
import numpy as np
from dbCon import DB_URI
from sqlalchemy import create_engine

engine = create_engine(DB_URI, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
sql = "select * from job1"
data =session.execute(sql).fetchall()
session.close()
text=""
file=open('analyze.txt','w')
for item in data:
    strs=str(item).replace("\n","")
    strs=strs.replace("'","")
    strs=strs.replace(" ","")
    strs=strs.replace("(","")
    strs=strs.replace(")","")
    text=text+strs
# with open("analyze.txt") as fp:
#     text=fp.read()
img = image.open(r'python.jpeg')
mask = np.array(img)
font="static/icon/方正粗黑宋简体.ttf"
# cut = jieba.cut(text)
# string = ' '.join(cut)
# print(len(string))

wc = WordCloud(
    background_color = 'white',
    font_path = font,
    mask=mask,
    max_words=100,
    max_font_size=100,
    random_state=30,
    scale=3,
    collocations=False
  ).generate(text)
wc.to_file("static/imgs/py.png")